package com.group01.web.controller;

import com.group01.annotation.SystemLog;
import com.group01.dto.Admin.AdminLoginDTO;
import com.group01.result.Result;
import com.group01.service.AdminService;
import com.group01.vo.Admin.AdminLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 认证模块
 * @Description
 * @Author 翟玉龙
 * @Date 2024/6/21
 */
@RestController
@RequestMapping("/admin")
@Validated
@Api(tags = "认证模块")
public class AdminController {

    /**
     * 注入业务
     */
    private final AdminService adminService;

    public AdminController(AdminService adminService) {
        this.adminService = adminService;
    }

    /**
     * 登录接口
     * @param adminLoginDTO 登录参数
     * @return {@link Result }
     */
    @ApiOperation("登录接口")
    @PostMapping("/login")
    @SystemLog(business = "管理员登录接口")
    public Result<AdminLoginVO> AdminLogin(
            @RequestBody @Validated AdminLoginDTO adminLoginDTO
    ) {
        return adminService.loginAdmin(adminLoginDTO);
    }

    /**
     * 退出登录
     * @return {@link Result }<{@link String }>
     */
    @PostMapping("/logout")
    @SystemLog(business = "管理员退出登录")
    public Result<String> AdminLogout() {
        return adminService.logoutAdmin();
    }

}
